using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PACKETPARSERMAX20.CORE;

namespace PACKETPARSERMAX20.CORE.DEFINITIONS
{
    public class CMSG_CAST_SPELL_DEF : DefinitionBase
    {

        public override bool Process()
        {
            ResetPosition();

            UInt16 cast_count;
            UInt32 spellId;
            byte unk_flags = 0;                                // flags (if 0x02 - some additional data are received)

            if (ClientBuild >= 9183)
            {
                cast_count = ReadByte();
                spellId = ReadUInt32();
                unk_flags = ReadByte();
            }
            else
            {
                spellId = ReadUInt32();
                cast_count = ReadByte();

            }


            if (ClientBuild <= 7799)
            {
                UInt16 unk = ReadUInt16();
            }
            else
            {
                UInt32 targetMask = ReadUInt32();
                SpellCastTargetFlags tSpellCastTargetFlags = (SpellCastTargetFlags)targetMask;


                if (tSpellCastTargetFlags == SpellCastTargetFlags.TARGET_FLAG_SELF)
                {
                    UInt64 PlayerGuid = Core.PlayerGUID;
                }

                // TARGET_FLAG_UNK2 is used for non-combat pets, maybe other?
                if ((targetMask & ((uint)SpellCastTargetFlags.TARGET_FLAG_UNIT | (uint)SpellCastTargetFlags.TARGET_FLAG_UNK2)) > 0)
                {
                    UInt64 guid = popGuid();
                }

                if ((targetMask & ((uint)SpellCastTargetFlags.TARGET_FLAG_OBJECT | (uint)SpellCastTargetFlags.TARGET_FLAG_OBJECT_UNK)) > 0)
                {
                    UInt64 guid = popGuid();
                }

                if ((targetMask & ((uint)SpellCastTargetFlags.TARGET_FLAG_ITEM | (uint)SpellCastTargetFlags.TARGET_FLAG_TRADE_ITEM)) > 0)
                {
                    UInt64 guid = popGuid();
                }

                if ((targetMask & (uint)SpellCastTargetFlags.TARGET_FLAG_SOURCE_LOCATION) > 0)
                {
                    if (ClientBuild >= 10314)
                    {
                        byte unk = ReadByte();
                    }

                    float x = ReadSingle();
                    float y = ReadSingle();
                    float z = ReadSingle();
                }

                if ((targetMask & (uint)SpellCastTargetFlags.TARGET_FLAG_DEST_LOCATION) > 0)
                {
                    if (ClientBuild >= 9551)
                    {
                        byte unk = ReadByte();
                    }

                    float x = ReadSingle();
                    float y = ReadSingle();
                    float z = ReadSingle();


                }

                if ((targetMask & (uint)SpellCastTargetFlags.TARGET_FLAG_STRING) > 0)
                {
                    string m_strTarget = ReadString();
                }

                if ((targetMask & (uint)SpellCastTargetFlags.TARGET_FLAG_PVP_CORPSE) > 0)
                {
                    UInt64 guid = popGuid();
                }
            }

            // some spell cast packet including more data (for projectiles?)
            if ((unk_flags & 0x02) > 0)
            {
                float a = ReadSingle();
                float b = ReadSingle();
                byte c = ReadByte();
                UInt32 d = ReadUInt32();
                //recvPacket.read_skip<float>();                      // unk1, coords?
                //recvPacket.read_skip<float>();                      // unk1, coords?
                //recvPacket.read_skip<uint8>();                      // >> 1
                //recvPacket.read_skip<uint32>();                     // >> MSG_MOVE_STOP
                //MovementInfo movementInfo;
                //ReadMovementInfo(recvPacket, &movementInfo);
            }

            return Validate();
        }
    }
}
